package com.bbs.service;

import java.util.List;

import com.bbs.dao.ArticleDao;
import com.bbs.dao.ReplyDao;
import com.bbs.entity.Article;
import com.bbs.entity.Reply;
import com.bbs.entity.User;
import com.bbs.util.DateUtil;
import com.bbs.util.Page;

public class ReplyService {

	private ReplyDao replyDao = new ReplyDao();
	
	public int save(String articleid,String pid, String content, User user) {
		Reply reply = new Reply();
		reply.setContent(content);
		reply.setCreatedate(DateUtil.getNow());
		reply.setPid(Integer.parseInt(pid));
		Article article = new ArticleDao().findById(Integer.parseInt(articleid));
		
		reply.setArticle(article);
		reply.setUser(user);
		
		return replyDao.save(reply);
	}

	/**
	 * 根据帖子ID删除对应所有回帖
	 * @param id
	 */
	public void deleteByAid(int id) {
		new ReplyDao().deleteByAid(id);
	}

	public int findReplyCount(String id) {
		return replyDao.findReplyCount(Integer.valueOf(id));
	}

	public List<Reply> findMineByUid(int id,Page page) {
		return new ReplyDao().findMineByUid(id,page);
	}

	public int getCountByuid(int id) {
		return new ReplyDao().getCountByuid(id);
	}
	
}
